package logic

import (
	"api/pkg"
	"context"
	"goods_srv/goodssrvclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsCreateLogic {
	return &GoodsCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsCreateLogic) GoodsCreate(req *types.GoodsCreateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	create, err := l.svcCtx.GoodsSrv.GoodsCreate(l.ctx, &goodssrvclient.GoodsCreateRequest{
		UserId:     int64(req.UserId),
		GoodsName:  req.GoodsName,
		GoodsTitle: req.GoodsTitle,
		GoodsPrice: float32(req.GoodsPrice),
		GoodsStock: int64(req.GoodsStock),
		GoodsCover: req.GoodsCover,
		GoodsIntro: req.GoodsIntro,
	})
	if err != nil {
		return &types.Response{
			Message: pkg.Sting(err.Error()),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "商品发布成功",
		Code:    200,
		Data:    create,
	}, nil
}
